package com.hr.controller.admin;

import com.hr.domain.po.Contract;
import com.hr.domain.query.ContractPageParams;
import com.hr.domain.query.ContractPageResult;
import com.hr.domain.vo.ContractVO;
import com.hr.service.ContractService;
import com.hr.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("管理端接口管理")
@RequestMapping("/admin")
@Tag(name = "后台房屋合同信息管理")
@AllArgsConstructor
public class ContractController {

    private final ContractService contractService;

    /**
     * 获取房屋合同列表
     * @return contractList
     */
    @GetMapping("/contract/list")
    @Operation(summary = "获取房屋合同列表")
    public Result getContractList() {
        log.info("获取房屋合同列表");
        List<ContractVO> contractList = contractService.getContractList();
        if (contractList == null){
            return Result.error("没有合同信息");
        }
        return Result.success(contractList);
    }

    /**
     * 分页获取房屋合同列表
     * @param queryParams
     * @return contractPageResult
     */
    @GetMapping("/contract/page")
    @Operation(summary = "分页获取房屋合同列表")
    public Result getContractPageList(ContractPageParams queryParams) {
        log.info("分页获取房屋合同列表");
        ContractPageResult contractPageResult = contractService.getContractPageList(queryParams);
        return Result.success(contractPageResult);
    }

    /**
     * 更新房屋合同状态
     * @param id
     * @param status
     * @return msg
     */
    @PutMapping("/contract/status")
    @Operation(summary = "更新房屋合同状态")
    public Result updateContractStatus(@RequestParam("id") Long id,
                                       @RequestParam("status") Integer status) {
        if(status != 1 && status != 0){
            return Result.error("状态值错误,请重新输入");
        }
        log.info("更新房屋合同状态");
        String msg = contractService.updateContractStatus(id, status);
        return Result.success(msg);
    }

    /**
     * 获取合同详情
     * @param id
     * @return contractVO
     */
    @GetMapping("/contract/detail")
    @Operation(summary = "获取合同详情")
    public Result getContractDetail(@RequestParam("id") Long id) {
        log.info("获取合同详情");
        ContractVO contractVO = contractService.getContractDetail(id);
        if (contractVO == null){
            return Result.error("没有合同信息");
        }
        return Result.success(contractVO);
    }



    // TODO:1.添加合同信息 2.更新合同信息 3.删除合同信息
}
